<?php

namespace app\official\controller;

use think\Controller;
// 微信公众号封装类
use EasyWeChat\Factory;
// 微信公众号配置
use addons\wechat\library\Config;

class Menu extends Controller
{

  // 微信属性
  protected $WeChat = null;

  public function __construct()
  {
    // 手动继承父级的构造函数
    parent::__construct();

    // 初始化配置
    $this->WeChat = Factory::officialAccount(Config::load());
    $this->order = model('Product.Order');
  }

  // 创建菜单
  public function create()
  {
    // 菜单数组
    $buttons = [
      [
        "type" => "click",
        "name" => "今日歌曲",
        "key"  => "海阔天空"
      ],
      [
        "name"       => "菜单",
        "sub_button" => [
          [
            "type" => "view",
            "name" => "H5stock",
            "url"  => "http://uniapphxj.gjjun.top"
          ],
          [
            "type" => "view",
            "name" => "云课堂",
            "url"  => "http://hxj.gjjun.top"
          ],
          [
            "type" => "click",
            "name" => "赞一下我们",
            "key" => "点赞成功"
          ]
        ]
      ]
    ];

    // 调用menu对象的创建菜单的方法
    $result = $this->WeChat->menu->create($buttons);

    if ($result) {
      echo '创建成功';
    } else {
      echo '创建失败';
    }
  }
  
  public function test()
  {
      $data = $this->order->find(13)->toArray();
      var_dump($data);exit;
  }
}
